<template>
  <div>
    <!-- 实名认证结果查询-->
    <TopFilter ref="topform" :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110" @resetChange="resetChange"></TopFilter>
    <FilterTables
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isSelectColumn="false"
      :datakey="'records'"
      columnsRef="RealNameAuthenticationQuery"
      :onColumnsChange="(columns) => (this.columns = columns)"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" @click="addHandle(1)">导 出</multiuse-button>
      </template>
    </FilterTables>
  </div>
</template>
<script>
import { getLevelOneArea } from '@/api/cms-common/dealerdata/index';
import { region } from '@/api/cms-common/region';
import { getList, exporturl, exporList } from '@/api/omSaleP/OrderManagement/RealNameAuthenticationQuery/index.js';
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile } from '@/utils';
import { dealerMixin } from '@/pages/repair/batchEventManagement/dealerMixin';
import moment from 'moment';
export default {
  name: 'RealNameAuthenticationQuery',
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: getList,
      fetchParams: {
        isDealer: 10041002,
      },
    };
  },
  mixins: [dictionary, dealerMixin, region],
  components: {},
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    //初始化所属区域数据
    this.getTopLevelArea();
    //初始化省份数据
    this.initProvince();
  },
  created() {},
  methods: {
    // 所属区域
    async getTopLevelArea() {
      const res = await getLevelOneArea(15061015);
      if (res.resultCode === 200) {
        this.topFilterList.find((item) => item.fieldName === 'areaId').itemList = res.data.map((x) => ({ value: parseInt(x.id), text: x.orgName }));
      }
    },
    //初始化所在省份
    async initProvince() {
      let pl = await this.createRegionList();
      this.topFilterList.find((item) => item.fieldName === 'provinceId').itemList = pl;
    },
    //初始化所在市数据
    async initCity(provinceId) {
      this.topFilterList.find((item) => item.fieldName == 'cityId').initialValue = '';
      this.topFilterList.find((item) => item.fieldName == 'cityId').itemList = [];
      if (!provinceId || provinceId == null || typeof provinceId == 'undefined') {
        return;
      }
      //取省数据
      let rd = this.getRegionData();
      this.cityData = rd[provinceId].children;
      let cl = this.createSubRegionList(this.cityData);
      //初始化市，清除原值
      let city = this.topFilterList.find((item) => item.fieldName === 'cityId');
      city.itemList = cl;
      city.initialValue = '';
    },
    async addHandle(type) {
      // let json = Object.assign({}, { CODE: 'CODE_0000006' }, this.fetchParams);
      // let res = await exporturl(json);
      // if (res.resultCode == 200) {
      //   this.$router.push('/admin/auth/oem/downloadCenter');
      // }

      this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
        confirmButtonText: '下载',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.$refs.topform.SUBMIT_FORM();
          let json = this.fetchParams;
          exporList(json)
            .then((response) => {
              exportExcelFile(response.data, '实名认证结果查询');
            })
            .catch((err) => {
              // console.log(err);
            });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          });
        });
    },
    changeHandle(params) {
      if (this.checkTime(params.createdStartDate, params.createdEndDate, 24)) {
        return this.$notify.warning({ title: '提示信息', message: '起止日期跨度不能超过两年' });
      }
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    resetChange(val) {
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    createdFrom() {
      return [
        {
          type: 'TEXT_AREA',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '输入多个VIN时，请用英文逗号或者换行隔开（例如：VIN1,VIN2……）',
          maxlength: '10000',
          maxRows: 2,
        },
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '输入多个经销商代码时，请用英文逗号隔开',
        },
        {
          type: 'INPUT',
          label: '经销商简称',
          fieldName: 'dealerName',
          placeholder: '请输入',
        },
        {
          type: 'SELECT',
          label: '所属区域',
          fieldName: 'areaId',
          placeholder: '请选择',
          itemList: [],
        },
        {
          type: 'SELECT',
          label: '省份',
          fieldName: 'provinceId',
          placeholder: '请选择',
          initialValue: '',
          itemList: [],
          change: (props) => this.initCity(props),
        },
        {
          type: 'SELECT',
          label: '城市',
          fieldName: 'cityId',
          placeholder: '请选择',
          initialValue: '',
          itemList: [],
        },
        {
          type: 'SELECT',
          label: '车主类型',
          fieldName: 'ownerTypeCode',
          placeholder: '请选择',
          itemList: this.createDictList('2140'),
        },
        {
          type: 'SELECT',
          label: '认证类型',
          fieldName: 'authTypeCode',
          placeholder: '请选择',
          itemList: this.createDictList('2141'),
        },
        {
          type: 'INPUT',
          label: '返回代码',
          fieldName: 'code',
          placeholder: '请输入',
          style: { width: 'calc(100% - 30px)' },
          descOptions: {
            isTooltip: true,
            content:
              '100：已提交;\n200：实名成功;\n1200：没有对应的车辆信息;\n1202：当前车辆无实名车主;\n1203:实名认证提交;\n1204：实名认证人工审核不通过;\n1205：已实名或实名认证处理中;\n1300：人证比对失败;\n1400：运营商 T1 接口一证十卡核验失败;\n1402：运营商 T1 接口同步失败;\n1403：运营商 T1 接口报竣失败;\n1500：实名服务系统异常;\n1501：CMP 系统处理失败',
            style: { left: '10px', float: 'right' },
          },
        },
        {
          type: 'RANGE_DATE',
          label: '创建日期',
          fieldName: 'createdStartDate|createdEndDate',
          placeholder: '请选择',
          initialValue: [],
          dateType: 'exactdaterange',
        },
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '所属区域',
          dataIndex: 'areaName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商代码',
          dataIndex: 'ownerCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商简称',
          dataIndex: 'dealerShortName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          width: 200,
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '车主类型',
          dataIndex: 'ownerTypeCode',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p) => {
            return <span>{this.createDictText(p.row.ownerTypeCode, '2140')}</span>;
          },
        },
        {
          title: '认证类型',
          dataIndex: 'authTypeCode',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: (p) => {
            return <span>{this.createDictText(p.row.authTypeCode, '2141')}</span>;
          },
        },
        {
          title: '返回代码',
          dataIndex: 'code',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '代码解释',
          dataIndex: 'resultCode',
          sorter: true,
          filter: true,
          width: 200,
          filterType: 'input',
          render: (p) => {
            return <span>{this.createDictText(p.row.resultCode, '2139')}</span>;
          },
        },
        {
          title: '创建时间',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          width: 150,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          filterType: 'date-range',
        },
      ];
    },
  },
};
</script>
